package com.example.myproject.redis.redission.service;

import org.apache.commons.lang3.StringUtils;

import java.util.*;

public class StringUtil extends StringUtils {
    public static final String EMPTY = "";
    public static final String SPACE = " ";
    public static final String STR_BR = "<br/>";
    public static final String STR_BR2 = "<br>";
    public static final String STR_STAR = "*";
    public static final String STR_SET = "set";
    public static final String STR_ZERO = "0";
    public static final String STR_ONE = "1";
    public static final String STR_DOT = ".";
    public static final String STR_COLON = ":";
    public static final String STRING_REVERSE_LEVER = "/";
    public static final String STR_SEMICOLON = ";";
    public static final String STR_ESCAPE = "\\";
    public static final String STR_UNDERLINE = "_";
    public static final String STR_COMMA = ",";
    public static final String STR_MIDDLELINE = "-";
    public static final String STR_PERCENT = "%";
    public static final String STR_QUOTE = "'";
    public static final String STRING_SHUGANG = "|";
    public static final String STR_COLON_SPACE = "：";
    public static final String SEPARATOR = "、";
    public static final String STR_TO = "=>";
    public static final String STR_FOLLOW_INDEX_IMPORT_DATE = "2015-01-01";
    public static final String STR_E = "E";
    public static final String SPACE_SBC = "　";
    public static final String STR_DIRECTION = " =》";
    public static final String STR_COMMA2 = "、";
    public static final String STR_DOUBLUE_QUOTE = "\"";
    public static final String STR_LFET_BRACE = "{";
    public static final String STR_RIGHT_BRACE = "}";
    public static final String STR_LFET_BRACKET = "[";
    public static final String STR_RIGHT_BRACKET = "]";
    public static final String STR_FONT_BEGIN = "<font color=\"red\">";
    public static final String STR_FONT_BEGIN_RED = "<font color='red'>";
    public static final String STR_FONT_BEGIN_GREEN = "<font color='green'>";
    public static final String STR_FONT_END = "</font>";
    public static final String STR_INTEGER_COLOR = "<span style='color:#333;' title='";
    public static final String STR_DECIMAL_COLOR = "<span style='color:#999;' title='";
    public static final String STR_DECIMAL_COLOR_BLACK = "<span style='color:#333;' title='";
    public static final String STR_COLOR_BEGIN = "'>";
    public static final String STR_COLOR_END = "</span>";
    public static final String MATCH_LETTER = "^[a-zA-Z]+$";
    public static final String MATCH_NUMBER = "^[0-9]+$";
    public static final String MATCH_NUMBER_CONTAIN_NEGATIVE = "^(-)?[0-9]+$";

    public StringUtil() {
    }

    public static String getString(Object o) {
        if (o == null) {
            return "";
        } else {
            return o instanceof String ? (String)o : String.valueOf(o);
        }
    }

    public static String getTrimString(Object o) {
        if (o == null) {
            return "";
        } else {
            return o instanceof String ? ((String)o).trim() : String.valueOf(o).trim();
        }
    }

    public static String join(List list) {
        return "'" + StringUtils.join(list, "','") + "'";
    }

    public static String convertDoubleToString(double d) {
        String s = getString(d);
        int indexE = s.indexOf("E");
        if (indexE == -1) {
            return s;
        } else {
            int afterE = Integer.valueOf(s.substring(indexE + 1));
            s = s.substring(0, indexE);
            s = s.replace(".", "");
            if (s.length() - 1 < afterE) {
                int x = afterE - (s.length() - 1);
                StringBuffer sb = new StringBuffer(s);

                for(int i = 0; i < x; ++i) {
                    sb.append(0);
                }

                s = sb.toString();
            }

            String s1 = s.substring(0, afterE + 1);
            String s2 = s.substring(afterE + 1);
            return isBlank(s2) ? s1 : s1 + "." + s2;
        }
    }

    public static String getHidePhone(String keyWords, String oriStr) {
        try {
            int i = oriStr.indexOf(keyWords) + 6;
            String s1 = "";
            String s2 = "";
            int indexEqual = oriStr.indexOf("=");

            int subEndIndex =0;
            if (oriStr.charAt(i) != '：') {
                subEndIndex = i;
            } else {
                subEndIndex = i + 1;
            }

            s1 = oriStr.substring(0, subEndIndex);
            if (indexEqual == -1) {
                s2 = "";
            } else {
                s2 = "[原] " + oriStr.substring(subEndIndex, indexEqual);
            }

            return s1 + s2;
        } catch (Exception var7) {
            var7.printStackTrace();
            return "";
        }
    }

    public static String toSBC(String input) {
        char[] c = input.toCharArray();

        for(int i = 0; i < c.length; ++i) {
            if (c[i] == ' ') {
                c[i] = 12288;
            } else if (c[i] < 127) {
                c[i] += 'ﻠ';
            }
        }

        return new String(c);
    }

    public static String toDBC(String input) {
        char[] c = input.toCharArray();

        for(int i = 0; i < c.length; ++i) {
            if (c[i] == 12288) {
                c[i] = ' ';
            } else if (c[i] > '\uff00' && c[i] < '｟') {
                c[i] -= 'ﻠ';
            }
        }

        return new String(c);
    }

    public static String getStatisticsNum(Object o) {
        if (o == null) {
            return "0";
        } else {
            return o instanceof String ? (String)o : String.valueOf(o);
        }
    }

    public static String lpad(int length, Long number) {
        String f = "%0" + length + "d";
        return String.format(f, number);
    }

    public static String trimLastComma(String src) {
        return src.endsWith(",") ? src.substring(0, src.length() - 1) : src.substring(0, src.length());
    }

    public static void joinUuidToStringBuilder(StringBuilder builder, String uuid) {
        if (builder.length() > 0) {
            builder.append(",");
        }

        builder.append("'");
        builder.append(uuid);
        builder.append("'");
    }

    public static void joinIdToStringBuilder(StringBuilder builder, Long id) {
        if (builder.length() > 0) {
            builder.append(",");
        }

        builder.append(id);
    }

    public static boolean strIsNumber(String str) {
        return isNotBlank(str) ? str.matches("^[0-9]+$") : false;
    }

    public static boolean strIsNumberContainNegative(String str) {
        return isNotBlank(str) ? str.matches("^(-)?[0-9]+$") : false;
    }

    public static boolean strIsLetter(String str) {
        return isNotBlank(str) ? str.matches("^[a-zA-Z]+$") : false;
    }

    public static boolean exist(String[] values, String value) {
        if (value == null) {
            return false;
        } else {
            int headLength = values.length;

            for(int i = 0; i < headLength; ++i) {
                if (equals(value, values[i])) {
                    return true;
                }
            }

            return false;
        }
    }

    public static String escape(String s) {
        StringBuilder sb = new StringBuilder();

        for(int i = 0; i < s.length(); ++i) {
            char c = s.charAt(i);
            if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':' || c == '^' || c == '[' || c == ']' || c == '"' || c == '{' || c == '}' || c == '~' || c == '*' || c == '?' || c == '|' || c == '&' || c == '/') {
                sb.append('\\');
            }

            sb.append(c);
        }

        return sb.toString();
    }

    public static Set<Long> splitIdStr2Set(String idsStr) {
        if (isBlank(idsStr)) {
            return null;
        } else {
            String[] ids = idsStr.split(",");
            Set<Long> idSet = null;
            String[] var3 = ids;
            int var4 = ids.length;

            for(int var5 = 0; var5 < var4; ++var5) {
                String idStr = var3[var5];
                if (!isBlank(idStr)) {
                    idStr = idStr.trim();
                    if (isNumeric(idStr)) {
                        if (idSet == null) {
                            idSet = new HashSet();
                        }

                        Long id = Long.valueOf(idStr);
                        idSet.add(id);
                    }
                }
            }

            return idSet;
        }
    }

    public static List<String> convertString2List(String value, String sptr) {
        if (StringUtils.isBlank(value)) {
            return null;
        } else {
            if (sptr == null) {
                sptr = ",";
            }

            List<String> result = new ArrayList();
            String[] array = value.split(sptr);
            String[] var4 = array;
            int var5 = array.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String str = var4[var6];
                if (StringUtils.isNotBlank(str)) {
                    result.add(str);
                }
            }

            return result;
        }
    }

    public static String convertList2String(List<String> value, String sptr) {
        if (value != null && !value.isEmpty()) {
            if (sptr == null) {
                sptr = ",";
            }

            StringBuffer stringBuffer = new StringBuffer();
            Iterator var3 = value.iterator();

            while(var3.hasNext()) {
                String str = (String)var3.next();
                stringBuffer.append(sptr);
                stringBuffer.append(str);
            }

            return stringBuffer.substring(sptr.length());
        } else {
            return null;
        }
    }
}
